/*
* @Author: root
* @Date:   2017-12-09 13:21:38
* @Last Modified by:   root
* @Last Modified time: 2017-12-09 14:20:16
*/
'use strict';
require('./index.css');
require('page/common/nav/index.js');
require('page/common/header/index.js');
var _utils          = require('util/util.js');
var _payment        = require('service/payment-service.js');
var templateIndex   = require('./index.string');

var page = {
	data : {
		orderNumber : _utils.getUrlParam('orderNumber')
	},
	init : function(){
		this.onload();
		
	},
	onload  : function(){
		
		//加载loadPaymentInfo数据  
		this.loadPaymentInfo();
	},
	//加载订单列表
	loadPaymentInfo : function(){
		var paymentHtml 	 = '',
					_this 	 = this,
					$pageWrap = $('.page-wrap');
					//$pageWrap.html('<div class="loading"></div>');
				   _payment.getPaymentInfo(this.data.orderNumber,function(res){
					
					paymentHtml = _utils.renderHtml(templateIndex,res);
					//渲染html
					$pageWrap.html(paymentHtml);
					_this.listenOrderStatus();
				},function(errMsg){
					$pageWrap.html('<p class="err-tip">'+errMsg+'</p>');
				});
	},
	//监听订单状态
	listenOrderStatus : function(){
		var _this = this;
		this.paymentTimer = window.setInterval(function(){
			_payment.getPaymentStatus(_this.data.orderNumber,function(res){
				if(res == true){
					window.location.href 
					= './result.html?type=payment&orderNumber='+_this.data.orderNumber;
				}	
			});
		},5e3)
	}
	
};
$(function(){
	page.init();
});
